<include file="public@header"/>
<style>
    .cas-thumbnail {
        width: 80px;
        height: 80px;
    }

    .table td, .table th {
        text-align: center;;
    }

    .js-add-to-stock-out-btn {
        cursor: pointer;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <form class="well form-inline" method="post" action="">
        CAS：
        <input type="text" class="form-control" name="cas" style="width:100px;" value="{:input('param.cas')}"
               placeholder="请输入CAS">
        关键字：
        <input type="text" class="form-control" name="keyword" style="width: 200px;" value="{:input('param.keyword')}"
               placeholder="请输入化合物名称/分子式">
        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger" href="{:url('AdminProduct/select')}?order_draft_id={}">清空</a>
    </form>
    <form class="js-ajax-form" action="" method="post">
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th></th>
                <th width="100">CAS号</th>
                <th>名称</th>
                <th width="130">品牌</th>
                <th>包装规格</th>
                <th>价格/元</th>
                <th width="70">库存量</th>
                <th>备货期/天</th>
            </tr>
            </thead>
            <php>
                $status=array("1"=>"上架","0"=>"下架");
                $top_status=array("1"=>"置顶","0"=>"");
                $recommend_status=array("1"=>"推荐","0"=>"");
            </php>
            <foreach name="packs" item="vo">
                <tr class="data-item-tr">
                    <td>
                        <input type="radio" class="js-check"
                               value="{$vo.id}"
                               name="js-name-radio"
                               data-name="CAS:{$vo.product.cas} 名称:{$vo.product.name} 规格{$vo.pack}{$vo.unit}/{$vo.packing_material},纯度：{$vo.purity}">
                    </td>
                    <td>{$vo.product.cas}</td>
                    <td>{$vo.product.name}</td>
                    <td>{$vo.brand}</td>
                    <td>{$vo.pack}{$vo.unit}</td>
                    <td>{$vo.price}</td>
                    <td>{$vo.inventory}</td>
                    <td>{$vo.lead_time}</td>
                </tr>
            </foreach>
        </table>
        <ul class="pagination">{$page}</ul>
    </form>
</div>
<img id="cas-thumbnail-bigger"
     style="position: fixed;top: 50%;left: 50%;width: 300px;height: 300px;margin-left: -150px;margin-top: -150px;display: none;box-shadow: 0px 0px 20px rgba(0,0,0,0.2);"/>
<script src="__STATIC__/js/admin.js"></script>
<script>
    Wind.use('noty3', function () {

    });
    $(function () {
        var $cas_thumbnail_bigger = $('#cas-thumbnail-bigger');
        $('.cas-thumbnail').hover(function () {
            $cas_thumbnail_bigger.attr('src', $(this).attr('src'));
            $cas_thumbnail_bigger.show();
        }, function () {
            $cas_thumbnail_bigger.hide();
        });

        $('.js-add-to-stock-out-btn').click(function () {
            var $this    = $(this);
            var $input   = $this.siblings('input');
            var quantity = $input.val();
            var packId   = $this.data('pack');

            addToStockOut(quantity, packId);

        });

        $('.js-add-to-stock-out-input').keydown(function (e) {
            if (e.keyCode == 13) {
                var $this    = $(this);
                var quantity = $this.val();
                var packId   = $this.data('pack');

                addToStockOut(quantity, packId);
            }
        });


    });

    $('.data-item-tr').click(function (e) {

        console.log(e);
        var $this = $(this);
        if ($(e.target).is('input')) {
            return;
        }

        var $input = $this.find('input');
        if ($input.is(':checked')) {
            $input.prop('checked', false);
        } else {
            $input.prop('checked', true);
        }
    });

    function confirm() {
        var selectedPack = {};
        $('.js-check:checked').each(function () {
            var $this = $(this);

            selectedPack = {
                id: $this.val(),
                name: $this.data('name')
            }
        });

        return selectedPack;
    }


</script>
</body>
</html>